package com.ruoyi.factorydata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.factorydata.domain.CraftProcessRelation;
import com.ruoyi.factorydata.service.ICraftProcessRelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工艺工序Controller
 * 
 * @author ruoyi
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/craftprocess/craftprocess")
public class CraftProcessRelationController extends BaseController
{
    @Autowired
    private ICraftProcessRelationService craftProcessRelationService;

    /**
     * 查询工艺工序列表
     */
    @PreAuthorize("@ss.hasPermi('craftprocess:craftprocess:list')")
    @GetMapping("/list")
    public TableDataInfo list(CraftProcessRelation craftProcessRelation)
    {
        startPage();
        List<CraftProcessRelation> list = craftProcessRelationService.selectCraftProcessRelationList(craftProcessRelation);
        return getDataTable(list);
    }

    /**
     * 导出工艺工序列表
     */
    @PreAuthorize("@ss.hasPermi('craftprocess:craftprocess:export')")
    @Log(title = "工艺工序", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CraftProcessRelation craftProcessRelation)
    {
        List<CraftProcessRelation> list = craftProcessRelationService.selectCraftProcessRelationList(craftProcessRelation);
        ExcelUtil<CraftProcessRelation> util = new ExcelUtil<CraftProcessRelation>(CraftProcessRelation.class);
        util.exportExcel(response, list, "工艺工序数据");
    }

    /**
     * 获取工艺工序详细信息
     */
    @PreAuthorize("@ss.hasPermi('craftprocess:craftprocess:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(craftProcessRelationService.selectCraftProcessRelationById(id));
    }



    /**
     * 新增工艺工序
     */
    @PreAuthorize("@ss.hasPermi('craftprocess:craftprocess:add')")
    @Log(title = "工艺工序", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CraftProcessRelation craftProcessRelation)
    {
        return toAjax(craftProcessRelationService.insertCraftProcessRelation(craftProcessRelation));
    }

    /**
     * 修改工艺工序
     */
    @PreAuthorize("@ss.hasPermi('craftprocess:craftprocess:edit')")
    @Log(title = "工艺工序", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CraftProcessRelation craftProcessRelation)
    {
        return toAjax(craftProcessRelationService.updateCraftProcessRelation(craftProcessRelation));
    }

    /**
     * 删除工艺工序
     */
    @PreAuthorize("@ss.hasPermi('craftprocess:craftprocess:remove')")
    @Log(title = "工艺工序", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(craftProcessRelationService.deleteCraftProcessRelationByIds(ids));
    }
}
